package systems;

import com.artemis.EntityProcessingSystem;
import com.artemis.ComponentMapper;
import com.artemis.Entity;

import components.Thruster;
import components.Position;
import components.Sprite;

import org.newdawn.slick.Image;
public class ThrustRenderSystem extends EntityProcessingSystem 
{
	private ComponentMapper<Thruster> thrust;
	private ComponentMapper<Position> pos;
	private ComponentMapper<Sprite> sprite;
	
	public ThrustRenderSystem()
	{
		super(Thruster.class, Position.class, Sprite.class);
	}
	
	public void initialize()
	{
		thrust = new ComponentMapper<Thruster>(Thruster.class, world);
		pos = new ComponentMapper<Position>(Position.class, world);
		sprite = new ComponentMapper<Sprite>(Sprite.class, world);
	}
	
	public void process(Entity e)
	{
		if(thrust.get(e).isThrusting())
		{
			if(thrust.get(e).getImage().getRotation() != pos.get(e).getTheta())
			{
				thrust.get(e).getImage().setRotation(pos.get(e).getTheta());
			}
			float offset = (sprite.get(e).getImage().getWidth() + thrust.get(e).getImage().getWidth())/2;
			thrust.get(e).getImage().drawCentered((float)(pos.get(e).getX() + Math.cos(Math.toRadians(180 + pos.get(e).getTheta())) * offset), (float)(pos.get(e).getY() + Math.sin(Math.toRadians(180 + pos.get(e).getTheta())) * offset));
		}
	}
}
